import httpProxy from "../utils/request";
import { URL } from "../config";
interface IUploadResponse {
  OSSAccessKeyId: string;
  host: string;
  policy: string;
  signature: string;
  success_action_status: number;
}
export async function getUploadMode() {
  return await httpProxy({
    url: `/admin/base/comm/uploadMode`,
    method: "GET",
  });
}
export async function getUploadparams() {
  return await httpProxy<IUploadResponse>({
    url: `/admin/base/comm/upload`,
    method: "POST",
  });
}

export async function uploadOssApi(
  key: string,
  file: any,
  data: IUploadResponse
) {
  const formData = new FormData();
  formData.append("key", key);
  formData.append("OSSAccessKeyId", data.OSSAccessKeyId);
  formData.append("policy", data.policy);
  formData.append("signature", data.signature);
  formData.append("file", file);
  const res = await httpProxy({
    url: `https://xunjinasd.oss-cn-hangzhou.aliyuncs.com`,
    method: "POST",
    data: formData,
  });
  // await httpProxy({
  //   url: `/admin/space/info/add`,
  //   method: "POST",
  //   data: {
  //     classifyId: 1,
  //     name: key,
  //     progress: 100,
  //     url: "https://xunjinasd.oss-cn-hangzhou.aliyuncs.com/app%2Fbase%2Fdece696eed5744e7bd91c0ef1f12eb8a_tongzhi.png",
  //     error: "",
  //     key,
  //   },
  // });
  return res;
}

export async function addSpace(host: string, name: string, file: any) {
  return await httpProxy({
    url: `/admin/space/info/add`,
    method: "POST",
    data: {
      classifyId: 2,
      name: file.name,
      progress: 100,
      type: file.type,
      url: `${host}/${name}`,
      error: "",
      key: name,
      fileId: file.id,
      size: file.file.size,
    },
  });
}
